package org.hw.algorithm;

import org.hw.algorithm.LinkedList.LinkNode;
import org.hw.algorithm.LinkedList.LinkedFactory;
import org.hw.algorithm.number.NumberFactory;
import org.hw.algorithm.searchUtil.SearchFactory;
import org.hw.algorithm.sortUtil.SortFactory;
import org.hw.algorithm.string.StringFactory;
import org.hw.algorithm.treeutil.TreeNode;

import java.util.*;

public class Main {


    public static void main(String[] args) {

        SearchFactory searchaFactory = new AlgorithmFactory().getSearchFactory();
        SortFactory sortFactory = new AlgorithmFactory().getSortFactory();
        LinkedFactory linkedFactory = new AlgorithmFactory().getLinkedFactory();


        //quicksort

        int[] arr = new int[]{0, 5, 8, 10, 15, 17, 22, 44, 56, 100};
//        int[] arr=new int[]{1,5,8,2,23,1,67,44,9,13};
//        int[] selectarr=sortFactory.selectionSort(arr);
//        int[] selectarr=sortFactory.insertSort(arr);
//        sortFactory.mergeSort(arr,0,arr.length-1,new int[arr.length]);
//        sortFactory.quickSort(arr,0,arr.length-1);
//        List<Integer> arrlist = sortFactory.bucketSort(arr);
//        int bs=org.hw.algorithm.AlgorithmFactory.binarySearch(arr,10);
//        System.out.println(bs);

        TreeNode root = new TreeNode(0);
        TreeNode n1 = new TreeNode(1);
        TreeNode n2 = new TreeNode(2);
        TreeNode n3 = new TreeNode(3);
        TreeNode n4 = new TreeNode(4);
        root.left = n2;
        root.right = n4;
        n2.left = n1;
        n2.right = n3;
//        boolean b=searchaFactory.searchBST(root,8);
//        System.out.println(b);

        LinkNode head = new LinkNode();
        head.value = 1;
        LinkNode node1 = new LinkNode();
        node1.value = 2;
        LinkNode node2 = new LinkNode();
        node2.value = 3;
        LinkNode node3 = new LinkNode();
        node3.value = 4;
        LinkNode node4 = new LinkNode();
        node4.value = 5;

        head.next = node1;
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = null;
//        LinkNode result=LinkedFactory.reverseLinkTemp3(head);
//        CommonUtils.printLink(result,false);
//        LinkNode resut2=linkedFactory.inversionLink(resutl);
//        while (resut2!=null){
//            System.out.println(resut2.value);
//            resut2=resut2.next;
//        }

//        System.out.println("最长公共子串：" + StringFactory.longestComSubstr1("abcdefg", "xabcfg"));
//        System.out.println("最长公共子序列：" + StringFactory.longestComSubSequence("abcdefg", "xabcfg"));
//        System.out.println("-----------------------------------");
//        System.out.println("最长公共子序列：" + StringFactory.longestComSubSequence("ABCDEFG", "XABYDFRE"));
//        System.out.println("最长公共子串：" + StringFactory.longestComSubstr1("ABCDEFG", "XABYDFRE"));
//        System.out.println(longestComSubstr("dabcefyg", "abcdfg"));
//        System.out.println(StringFactory.doubleStr("dabcedfyg"));
//        StringFactory.permutations("abc".toCharArray(),0,2);
//        List<String> res=new ArrayList<>();
//        StringFactory.permutations("abc".toCharArray(), new ArrayList<Character>(),res);
//        res.forEach(System.out::println);
//        TreeFactory.recursiveTree(root);
//        System.out.println(NumberFactory.maxSubArr(new int[]{-2, 1, -3, 4, -1, 2, 1, -5, 4}));
//        System.out.println(StringFactory.longestPalindrom("eabcbafg"));
        System.out.println(SearchFactory.binarySearch(new int[]{10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 33, 35, 42, 47},16));
    }



}
